#include <my_test_lib.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>

#include <unistd.h>
#include <signal.h>
#include <sys/types.h>

void 
say_hello(void)
{
	printf("hello world!!\n");
}

int
my_max_int(int a,int b)
{
	return (a > b) ? a : b;
}

float
my_max_float(float a,float b)
{
	return (a > b) ? a : b;
}

double
my_max_double(double a,double b)
{
	return (a > b) ? a : b;
}

void
direct_select_sort(char *s,int len)
{
	int i,j;
	char tmp_s;
	for(i = 1;i < len;++i) {
		tmp_s = s[i];
		for(j = i - 1;j >= 0;--j) {
			if(s[j] > tmp_s) {
				s[j + 1] = s[j];
			} else {
				break;
			}
		}
		s[j + 1] = tmp_s;
	}
}

char *
return_string_buf(void)
{
	char *s = (char *)malloc(20);
	bzero(s,20);
	sprintf(s,"my hello world");
	return s;
}

void
return_memery_buf(uint8_t **buf,int *len)
{
	*len = 10;
	//printf("%p\n",buf);
	uint8_t *buf_a = (uint8_t *)malloc(*len);
	buf = &buf_a;
	/**buf = (uint8_t *)malloc(*len);
	for(int i = 0;i < *len;++i) {
		*buf[i] = i;
	}*/
}

void
shell_sort(int *a,int len)
{
	int i,j,h;
	int tmp;
	for(h = len / 2;h > 0;h /= 2) {
		for(i = h;i < len ;i += h) {
			tmp = a[i];
			for(j = i - h;j >= 0;j -= h) {
				if(a[j] > tmp) {
					a[j + h] = a[j];
				} else {
					break;
				}
			}
			a[j + h] = tmp;
		}
	}
}

bool 
get_stu_info(stu_info *stu)
{
	const char *id = "123456789abcdef";
	const char *name = "zhangshan";
	bzero(stu->id,16);
	memcpy(stu->id,id,15);
	stu->name_len = strlen(name);
	stu->name = (char *)malloc(stu->name_len + 1);
	bzero(stu->name,stu->name_len + 1);
	memcpy(stu->name,name,stu->name_len);
	stu->age = 16;
	stu->is_sleep_in_school = true;
	bzero(stu->reverse,3);
	return true;
}
